Help on eval_ function

Can someone help me with the mistake in this syntax:
 

Module mod1 = module(item)
string AttrName_to_check = "Attribute Name"
string temp = "if ( \"" null " \"" mod1.AttrName_to_check ") return_ " " \"failed\""
string temp1 = eval_ (temp)

 


This script tries to check the existence of module attribute; returns "failed", if the attribute does not exist in the module.

 


chidamla - Wed Feb 16 07:06:51 EST 2011

Re: Help on eval_ function
ChidambaramL - Wed Feb 16 07:34:05 EST 2011

Error recieved is:
-E- DXL: <Line:3> incorrectly concatenated tokens
-E- DXL: <Line:3> incorrectly concatenated tokens

Re: Help on eval_ function
Peter_Albert - Wed Feb 16 08:18:08 EST 2011

ChidambaramL - Wed Feb 16 07:34:05 EST 2011
Error recieved is:
-E- DXL: <Line:3> incorrectly concatenated tokens
-E- DXL: <Line:3> incorrectly concatenated tokens

I am pretty sure your code won't work, even if you resolved the syntax errors. eval_ code is afaik executed at the top level, hence the variable 'mod1' will not be existing, as well as 'AttrName_to_check', once the code is executed. Even if the variables existed, if the attribute does not exist in 'mod1', a call to 'mod1.AttrName_to_check' will just throw an error message (instead of being able to check for 'null', as you plan to do).

But if you just want to check whether 'AttrName_to_check' exists as a module level attribute in the module for which ypu have the item handle, then the following is sufficient:

string sAttName = "AttrName_to_check"
AttrDef ad = find(module item, sAttName)
if (!null ad)
{ // The attribute exists, now check whether it is a module and / or object level attribute
  if (ad.module){print "'" sAttName "' is a module level attribute\n"}
  if (ad.object){print "'" sAttName "' is an object level attribute\n
} // The attribute exists, now check whether it is a module and / or object level attribute
else {"No attribute '" sAttName "'\n"}

 


Regards,

Peter

 

Re: Help on eval_ function
llandale - Wed Feb 16 16:57:08 EST 2011

This works:

Module mod1 = current()
string AttrName_to_check = "Gads"
string temp = "return_ \"OK\";if ( null \"" probeAttr_(mod1, AttrName_to_check) "\") return_ " " \"failed\""
string temp1 = eval_ (temp)
 
print "Results = " temp1 "\n"


Note using probeAttr_ resolves the case when "Gads" doesn't exist as a module attribute.

Notice that "return_" is not the same as "return", it just sets the return value to be used when the eval_ code ends. In the above case, I set it to "OK" but it gets set to "failed" if the module-attr is null.

Your original had the problem of concatenating null with a string (e.g. what does it mean to concatenate a Module handle with a string???); you needed to concatenate the string "null".

 

 

  • Louie